// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:io';

import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:camera_platform_interface/src/method_channel/method_channel_camera.dart';

import '../camera.dart';
import 'android_camera.dart';
import 'avfoundation_camera.dart';
import 'ohos_camera.dart';

abstract class CameraPlatformV2 extends CameraPlatform {

  /// The default instance of [CameraPlatform] to use.
  ///
  /// Defaults to [MethodChannelCamera].
  static CameraPlatformV2 get instance => CameraPlatform.instance as CameraPlatformV2;

  static init() {
    CameraPlatform pi = CameraPlatform.instance;
    if(pi is MethodChannelCamera) {
      if(Platform.isAndroid) AndroidCamera.registerWith();
      else if(Platform.isIOS) AVFoundationCamera.registerWith();
      else if(Platform.operatingSystem == 'ohos') OhosCamera.registerWith();
      // if(kIsWeb) CameraPlugin.registerWith(null);
    }
  }

  Future<XFile> takePictureV2(int cameraId,{String? filePath, int orientation = 0, bool sound = false});

  Future<void> startVideoRecordingV2(int cameraId,
      {Duration? maxVideoDuration,String? filePath, required int videoFrameRate, required int videoBitRate});

  Future<double> setBrightnessOffset(int cameraId, double offset);

  Future<int> createCameraV2(
      CameraDescription cameraDescription,
      String? resolutionPreset, {
        bool enableAudio = false, int overlayWidth = 0, int overlayStyle = 0,
      });

  Future<bool> overlayPermission();
  Future<bool> hasOverlayPermission();

  void keepOn(bool on);

  /// Returns the resolution preset as a String.
  String serializeResolutionPreset(ResolutionPreset? resolutionPreset, ImageRatio? ratio) {
    switch (resolutionPreset) {
      case ResolutionPreset.max:
        return 'max';
      case ResolutionPreset.ultraHigh:
        return 'ultraHigh';
      case ResolutionPreset.veryHigh:
        return 'veryHigh';
      case ResolutionPreset.high:
        return 'high';
      case ResolutionPreset.medium:
        return 'medium';
      case ResolutionPreset.low:
        return 'low';
    }
    switch (ratio) {
      case ImageRatio.ratio_1_1:
        return 'R11';
      case ImageRatio.ratio_4_3:
        return 'R43';
      case ImageRatio.ratio_16_9:
        return 'R169';
    }
    // The enum comes from a different package, which could get a new value at
    // any time, so provide a fallback that ensures this won't break when used
    // with a version that contains new values. This is deliberately outside
    // the switch rather than a `default` so that the linter will flag the
    // switch as needing an update.
    // ignore: dead_code
    return 'high';
  }
}
